﻿
using AutoMapper;
using B.S.Sterilizationcenter.Domain.yjb;
using B.S.Sterilizationcenter.ErrorCode;
using B.S.Sterilizationcenter.Read.API.Appliaction.Commends.yjb;
using MediatR;
using SqlSugar;

namespace B.S.Sterilizationcenter.Read.API.Appliaction.CommandHandlers.yjb
{
    public class ShowProgramInfoCommandHandlers : IRequestHandler<ShowProgramInfoCommand, ApiResult<List<ProgramInfo>>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;

        public ShowProgramInfoCommandHandlers(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<List<ProgramInfo>>> Handle(ShowProgramInfoCommand request, CancellationToken cancellationToken)
        {
            try
            {
                ApiResult<List<ProgramInfo>> result = new ApiResult<List<ProgramInfo>>();
                var list = db.Queryable<ProgramInfo>().Where(x => x.IsDElete == false).ToList();

                //if (!string.IsNullOrEmpty(request.ConsumableCode))
                //{
                //    list = list.Where(it => it.ConsumableCode.Contains(request.ConsumableCode)).ToList();
                //}
                //if (!string.IsNullOrEmpty(request.ConsumableName))
                //{
                //    list = list.Where(it => it.ConsumableName.Contains(request.ConsumableName)).ToList();
                //}
                result.Code = ApiEnums.查询成功;
                result.Msg = "查询成功";
                result.Data = list;
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
